net: fix SocketAddress.parse default port handling#62912
net: fix SocketAddress.parse default port handling#62912araujogui wants to merge 5 commits intonodejs:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes net.SocketAddress.parse() so it correctly preserves explicit default ports (notably :80) that are otherwise dropped by URL.parse() when using an http:// base, aligning behavior with expectations and documentation.
Changes:
- Update
SocketAddress.parse()to derive the port from the raw input string rather thanurl.port. - Simplify the parse return path to a single
SocketAddressconstruction for both IPv4 and IPv6. - Add regression tests covering IPv4/IPv6 with explicit ports
80and443.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
lib/internal/socketaddress.js |
Fixes default-port handling by parsing the port from the raw input instead of URLParse(...).port. |
test/parallel/test-socketaddress.js |
Adds regression coverage ensuring explicit :80/:443 are preserved for both IPv4 and IPv6. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62912 +/- ##
==========================================
- Coverage 91.48% 89.63% -1.86%
==========================================
Files 358 708 +350
Lines 151591 220421 +68830
Branches 23925 42278 +18353
==========================================
+ Hits 138690 197578 +58888
- Misses 12625 14705 +2080
- Partials 276 8138 +7862
🚀 New features to boost your workflow:
|
b274a64 to
87d545a
Compare
87d545a to
7563aff
Compare
|
I noticed one extra behavior change from parsing the port with For example, current SocketAddress.parse('user:[email protected]')
SocketAddress.parse('user:[email protected]')With this patch they become ports An alternative is to keep using the HTTP URL parse for the address and existing non-default ports, and only when URLParse(`socket://${input}`).portThat preserves the existing URL host parsing while recovering explicit host ports like |
Great finding and solution, thank you @cookesan |
Actually, I did some benchmarks and noticed the double |
Fixes #62906